home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
183_01
/
dirgt.asm
< prev
next >
Wrap
Assembly Source File
|
1985-10-27
|
14KB
|
325 lines
page ,132
title **** DIRGT.ASM ***
comment *
=========================================================================
DIRGT.ASM
03-06-85 by Thomas E. Link
Procedure to be called from IBM PASCAL V2.0 or function in LATTICE C
to get disk directory including VOLUME NAME, file LENGTH,DATE, and TIME.
To use in PASCAL first:
type dirrect = record
fname:string(12);
ftime:word;
fdate:word;
flen:array[0..1] of word;
end;
lookst = string(40);
volst = string(13);
countt = word;
var dir_rec : array[0..111] of dirrect;
looks := 'drive id:\path\filename.ext'+CHR(0)
' name to search for, same as with DIR command
' path works only when used with DOS 2.x
' This string must terminate with a CHR$(0) !
procedure DIRGET(var looks lookst; var dir_rec[0]:dirrect;
var vols:volst; var count:countt);extern;
If Assembling for PASCAL leave the equate (pascal equ 1) below.
If using LATTICE C delete that line.
=========================================================================
*
pascal equ 1
page
workstruc struc
dircount dw (?)
dos_version db (?)
filler db (?)
saved_sp dw (?)
fcb db 48 dup (?)
dta db 48 dup (?)
workstruc ends
ifdef pascal ;-------------------------------------------------------
stack struc ; Define the stack area for PASCAL
workarea db type workstruc dup (?)
pushed_bp dw (?)
return dw (?)
address dw (?)
countnumad dw (?)
volstrgad dw (?)
dirrecarad dw (?)
lookstringad dw (?)
stack ends
poplen equ lookstringad - address
else ;-----------------
stack struc ; Define the stack area for C.
workarea db type workstruc dup (?)
pushed_bp dw (?)
address dw (?)
countnumad dw (?)
volstrgad dw (?)
dirrecarad dw (?)
lookstringad dw (?)
stack ends
poplen equ 0
endif ;---------------------------------------------------------------
data segment public 'DATA'
data ends
dgroup group data
ifdef pascal ;---------- Pascal --------------------------------------
prog segment public 'CODE'
assume CS:prog, DS:nothing, ES:nothing
public DIRGET
DIRGET proc far
else ;----------------- C definitions
pgroup group prog
assume CS:pgroup, DS:nothing, ES:nothing
prog segment public 'PROG'
public DIRGET,_DIRGET,DIRGET_
DIRGET proc near
endif ;----------------------------------------------------------------
page
DIRGET_:
_DIRGET:
cld ; Clear direction flag.
push bp
mov bp,sp ; Point to arguments on stack.
sub bp,type workstruc ; Give us room to work
mov [bp].saved_sp,sp ; Save the stack pointer
mov sp,bp ; and move it below workarea.
mov [bp].dircount,0 ; Move zero to directory count.
;----------------- determine DOS version, store in variable
mov ah,48 ; find DOS version number
int 21h
mov [bp].dos_version,al ; and store in variable
;----------------- parse filename
mov ax,ss
mov es,ax ; Have ES point at STACK **************
mov di,bp ; and DI point
add di,offset fcb ; to FCB area.
mov si,[bp].lookstringad ; Point SI at file specifier
mov ah,29H ; DOS function to parse filename
mov al,1 ; scan off leading separators
int 21H ; DOS function call
push ds ; Get DATA seg into ES.***************
pop es
cmp al,0FFH ; Any errors on parsing ?
jne dir2 ; No - continue
jmp done ; YES - end.
;----------------- get addresses of the parms
dir2:
mov dx,bp ; Put address of workspace into DX
add dx,offset dta ; Bump to DTA
push ds ; Save value of DS
mov ax,ss ; and move STACK into DS.**************
mov ds,ax
mov ah,1AH ; Set AH for *SET DTA* function call.
int 21H ; Use DOS interrupt.
cmp [bp].dos_version,2 ; if DOS 2.0 or greater
jae dos2_search ; use special routine
;----------------- DOS 1.0, 1.1 search
mov dx,bp ; Point DX at workspace
add dx,offset fcb ; bump to FCB area.
mov ah,11H ; Set AH for directory search.
int 21H ; Use DOS interrupt.
cmp al,0FFH ; Any matches found ?
je done1 ; No - so end
inc [bp].dircount ; Yes - count first entry.
call move ; Go move entry into fnames().
dirloop:
mov ah,12H ; Set AH for continuation of search.
int 21H ; Use DOS interrupt.
cmp al,0FFH ; Any matches found ?
je done1 ; No - jump to exit
inc [bp].dircount ; Yes - count this entry.
call move ; Go move entry into arrays.
jmp dirloop ; Do again.
;----------------- DOS 2.x search
dos2_search:
mov dx,[bp].lookstringad ; Point DX at file specifier
mov ah,4EH ; Set AH for directory search.
mov cx,10H ; search for files and directories.
int 21H ; Use DOS interrupt.
jc findlabel ; No matches - so look for a label
inc [bp].dircount ; found - count first entry.
call move2 ; Go move entry into arrays.
dir2loop:
mov cx,10H
mov ah,4FH ; Set AH for continuation of search.
int 21H ; Use DOS interrupt.
jc findlabel ; No matches - so look for a label
inc [bp].dircount ; match - count this entry.
call move2 ; Go move entry into arrays.
jmp dir2loop ; Do again.
findlabel:
call get_label ; look for a volume label
done1:
pop ds ; restore DS to DATA ****************
done:
mov ax,[bp].dircount ; Move entries count to AX.
mov di,[bp].countnumad ; Get address of COUNT%
mov [di],ax ; Put entry count in COUNT%.
mov sp,[bp].saved_sp ; Restore SP.
pop bp ; Restore BP.
ret poplen ; Return and throw away parms if PASCAL
;........................................................................
;----------------- procedure to store results from DOS 1.x search
move proc near
;----------------- first move filename into string array
mov di,[bp].dirrecarad ; Move name address to DI and BX.
mov bx,di
add bx,20 ; Have BX point at next record
mov [bp].dirrecarad,bx ; and save in variable
mov si,bp
add si,offset dta+1 ; put file name(in DTA) address into SI
mov cx,4 ; Length of name in words
rep movsw ; Move name into array.
mov byte ptr [di],'.' ; Put period in filename.
inc di ; Bump DI past '.'
mov cx,3